﻿using Engine;
using Game;
using GameEntitySystem;

namespace SCIENEW
{
	public class SorterDevice : DefaultDevice, IEntityDevice<ComponentChest> {
        public int FrontSlot, LeftSlot, BackSlot, RightSlot, VerticalSlot;

        public SorterDevice() : base("SorterDevice") {
            FrontSlot = 167;
            LeftSlot = 200;
            BackSlot = 185;
            RightSlot = 201;
            VerticalSlot = 170;
        }
		public string GetEntityName(int value) => "Sorter";

		public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
		{
			return new BlockPlacementData { Value = DevicesBlockManager.GetDeviceValue(Id, DevicesUtils.GetDirectionXZ(componentMiner, true)), CellFace = raycastResult.CellFace };
		}

		public Widget GetWidget(IInventory inventory, ComponentChest component) => new SorterWidget(inventory, component);

		public override DeviceBehavior[] GetBehaviors(Project project) => [new SorterDeviceBehavior(project)];

		public override int GetDisplayOrder(int value) => base.GetDisplayOrder(value) - 2;

        public override int GetFaceTextureSlot(int face, int value) {
            if (face == 0) return FrontSlot;
            if (face == 1) return LeftSlot;
            if (face == 2) return BackSlot;
            if (face == 3) return RightSlot;
            return VerticalSlot;
        }
    }
}